#include"EnvironmentSelectionSteadyStateModel.h"
#include"Evaluation.h"
#include"MemeticAlgorithm.h"

using namespace std;

vector<Solution> EnvironmentSelectionSteadyStateModel::Select(const vector<Solution>& parents , const vector<Solution>& children)
{
	vector<Solution> answer = parents;
	Solution worstParentNow = parents.front();
	int worstScoreNow = worstParentNow.getEvaluate();
	int worstParentIndex = 0;
	//--
	for(int index = 0 ; index < MemeticAlgorithm::POPULATION_SIZE ; ++index)
	{
		Solution whichParent = parents[index];
		int score = whichParent.getEvaluate();
		if(score > worstScoreNow)
		{
			worstParentNow = whichParent;
			worstScoreNow = score;
			worstParentIndex = index;
		}
	}

	Solution bestChildNow = children.front();
	int bestScoreNow = bestChildNow.getEvaluate();
	//--
	for(Solution whichchild : children)
	{
		int score = whichchild.getEvaluate();
		if(score < bestScoreNow)
		{
			bestChildNow = whichchild;
			bestScoreNow = score;
		}
	}
	answer[worstParentIndex] = bestChildNow;
	return answer;
}